import Vue from 'vue'
import App from './App.vue'
// import router from './router'
import Vuex from 'vuex'

// 让Vue使用Vuex
Vue.use(Vuex)
// 创建一个store实例
const store = new Vuex.Store({
  state: {
    goodList: [
      {
        name: '诸葛亮',
        price: 1000,
        num: 1,
        checked: false,
      },
      {
        name: '蔡文姬',
        price: 1500,
        num: 1,
        checked: false,
      },
      {
        name: '妲己',
        price: 2000,
        num: 1,
        checked: false,
      },
      {
        name: '鲁班',
        price: 2200,
        num: 1,
        checked: false,
      },
    ],
  },
  mutations: {
    // 数量添加事件
    addNum(state, index) {
      state.goodList[index].num ++
    },
    // 数量减少事件
    redNum(state, index) {
      state.goodList[index].num --
    },
    // 删除事件
    Delete(state, index) {
      state.goodList.splice(index,1)
    }
  },
})

Vue.config.productionTip = false

new Vue({
  store,
  render: (h) => h(App),
}).$mount('#app')
